package com.github.baichuan.application.scaffold.rest.jpa.app;

import com.github.baichuan.application.scaffold.rest.domain.app.App;
import com.github.baichuan.application.scaffold.rest.domain.app.AppVersion;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Optional;

public interface AppVersionRepository extends JpaRepository<AppVersion, Integer>, JpaSpecificationExecutor<AppVersion> {
    @Query("select appVersion from AppVersion appVersion where app=:app and version=:version")
    Optional<AppVersion> find(@Param("app") App app, @Param("version") String version);

    @Query("select appVersion from AppVersion appVersion where app=:app order by version desc limit 1")
    Optional<AppVersion> findLatestVersion(@Param("app") App app);

    void deleteByApp(App app);
}
